Iterated Fact Sheets With R Markdown

Iterated Fact Sheets With R Markdown

Aaron R. Williams (@awunderground)

Urban Institute

Urban Institute



Who we are

  • 300 researchers
  • 50 years

What we do

Our mission is to open minds, shape decisions, and offer solutions through economic and social policy research.

Our objective research helps expand opportunities for all, reduce hardship among the most vulnerable, and strengthen the effectiveness of the public sector.

  • Tax Policy Center analysis of candidate tax plans
  • Health Policy Center analysis of insurance coverage (King vs. Burwell)
  • Pioneers of paired testing and microsimulation

Why?

Motivation

Getting information into the right hands is important.

Motivation

Our reports often seem like this.

Motivation

Our attention spans are trained for this.

## [1] "https://imgs.xkcd.com/comics/boyfriend.png"

Economic and social policy comic strips

Economic and social policy comic strips Iterated fact sheets and web pages

What does this look like?

1. Targeted and brief

What does this look like?

2. Visually appealing (and branded)

Urban Institute data visualization style guide

What does this look like?

3. Not labor intensive

cat

What?

Examples

How?

R Markdown

.Rmd

  • Text and images
  • Code
  • Code output

Three ingredients for fact sheets/pages

  1. Data structure
  2. Parameterized .Rmd template
  3. Iterating script

1) Data structure

state_name hhpop horate medhhincome
Alabama 1846380 0.6814329 44700
Alaska 250183 0.6311860 70600
Arizona 2463012 0.6206178 51000
Arkansas 1144657 0.6546031 42000
California 12895471 0.5372219 64600
Colorado 2074517 0.6389425 63500
Connecticut 1343704 0.6623386 71700
Delaware 352597 0.7096147 61200
  • Typically with one row per fact sheet/page

2) Parameterized .Rmd template

Parameters for R Markdown documents are specified in the YAML header:

---
params:
  state: "Alabama"
  year: 2016
---

Parameters can then be used throughout the document:

There were 'r data$fatalities' traffic fatalities in 'r params$state' in 'r params$year'. 

There were 1,038 traffic fatalities in Alabama in 2016.

2) Parameterized .Rmd template

2) Parameterized .Rmd template

  • LaTeX for .pdf
  • CSS for .html
  • CSS for .md

3) Iterating script


Fact Sheet Tool

Fact Page Tool

Process

  1. Why fact sheets?
  2. Create a Word template
  3. Create and iterate the .Rmd
  4. Quality control
  5. Create a home for the fact sheets

Questions

Reach out to me

References

References

NHTSA Traffic Safety Fact Sheets

Texas Statehouse - LoneStarMike

Encyclopedia - WestportWiki